<?php
declare(strict_types=1);


namespace App\Mall\Mapper;

use App\Mall\Model\MallShop;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 商店列表Mapper类
 */
class MallShopMapper extends AbstractMapper
{
    /**
     * @var MallShop
     */
    public $model;

    public function assignModel()
    {
        $this->model = MallShop::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        return $query;
    }

    public function select(): array
    {
        return $this->model::query()->select(['id', 'name'])->get()->map(function ($item) {
            $item->name = fastapp_lang_text($item->name);
            return $item;
        })->toArray();
    }

    public function save(array $data): mixed
    {
        $data['admin_id'] = user()->getId();
        return parent::save($data);
    }
}